﻿using System;

namespace Ndns.Packet.Abstractions
{
    public class DnsQuery : IEquatable<DnsQuery>
    {
        /// <summary>
        /// 表示DNS查询的名称。
        /// </summary>
        public DnsHostName HostName { get; set; }

        /// <summary>
        /// 表示DNS的查询类型。
        /// </summary>
        public DnsRecordType Type { get; set; }

        /// <summary>
        /// 表示DNS的类型。
        /// </summary>
        public DnsClass Class { get; set; }


        #region Equals,HashCode实现

        
        public virtual bool Equals(DnsQuery other)
        {
            if (other == null)
                return this == null;

            if (this == null)
                return false;

            if (ReferenceEquals(this, other))
                return true;

            return HostName == other.HostName && Type == other.Type && Class == other.Class;
        }

        public override bool Equals(object obj)
        {
            if (obj is DnsQuery q)
                return Equals(q);
            return false;
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int total = 17;
                total = total * 37 + HostName.GetHashCode();
                total = total * 37 + Type.GetHashCode() << 16 | Class.GetHashCode();
                return total;
            }
        }

        #endregion

        public virtual DnsQuery Clone()
        {
            return new DnsQuery
            {
                HostName = HostName,
                Type = Type,
                Class = Class
            };
        }

    }
}
